<?php

/**
 * 审核餐厅AJAX
 * 
 * @copyright xinwei
 * @since 2012-04-11
 */

include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	//check refer  -  add by xinwei
	if(! security_check::check_refer())
	{
		throw new Exception("来路不明");
	}
	
	//餐厅ID
	cgi::get($g_cgival["rstrt_ids"], "rstrt_ids", "");
	$g_cgival["rstrt_ids"] = string::un_script_code($g_cgival["rstrt_ids"]);
	$g_cgival["rstrt_ids"] = string::un_html($g_cgival["rstrt_ids"]);
	
	//审核状态
	cgi::get($g_cgival["verify"], "verify", 0);
	$g_cgival["verify"] = intval($g_cgival["verify"]);
	if($g_cgival["verify"]!= 1 && $g_cgival["verify"]!= 2)
		throw new Exception("审核状态参数错误");

}

function get_data()
{
	global $g_cgival, $g_pro, $g_show;
	
	$db = new db_web_rstrt();
	$admin_log = new admin_log();
	
	$site_id = admin::admin_get_user_site_id();	// 拿到当前站点的site_id
	$admin_id = admin::admin_get_login_uid();	// 拿到当前管理员ID
	$admin_name = admin::admin_get_login_user_name();	// 拿到当前管理员用户名
	
	$idArr = explode(",",$g_cgival["rstrt_ids"]);
	
	//检查餐厅是否存在
	$check = $db->admin_get_rstrt_by_ids($idArr);
	$num_rec = count($idArr);//接收到的专辑数量
	$num_check = count($check);//数据库中检索到的专辑数量
	
	if($num_rec != $num_check)
	{
		throw new Exception('您操作的这组ID中有不存在的餐厅');
	} 
	
	//检查权限是否正常 排除总站帐号
	$check = $db->admin_check_rstrt_site_by_ids_site($idArr,$site_id);
	if($check)
	{
		throw new Exception("您操作的这组ID中有您无权操作的餐厅");
	}

	// 更新餐厅审核状态
	$update = $db->verify_rstrt_by_ids($idArr,$g_cgival["verify"]);
	if(!$update)
	{
		throw new Exception("审核失败");
	}
	
	if ($g_cgival["verify"] == 1)
	{
		$admin_log->admin_insert_log_info($admin_id, $site_id, 18, "审核通过 餐厅id={$g_cgival["rstrt_ids"]}");
	}
	else
	{
		$admin_log->admin_insert_log_info($admin_id, $site_id, 18, "驳回 餐厅id={$g_cgival["rstrt_ids"]}");
	}
}

$g_show["error"] = 0;
$g_show["errmsg"] = '';

try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/ajax_album_verify_op.php");
	
	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	if(isset($_GET['debug']))
		print_r($g_show);
	echo output::json('json',$g_show);
}

?>